package com.java.throwable;

import java.io.*;

/**
 * throws
 */
public class Throws {
    public static void func1(String path) throws FileNotFoundException, IOException { // throws抛出异常给方法调用者
        File file = new File(path);
        String result;
        BufferedReader reader = new BufferedReader(new FileReader(file));
        while ((result = reader.readLine()) != null) {
            System.out.println(result);
        }
        reader.close();
    }
    
    public static void func2(String path) throws FileNotFoundException, IOException { // throws抛出异常给方法调用者
        func1(path);
    }
    
    public static void main(String[] args) throws FileNotFoundException, IOException {
        System.out.println("方法开始");
        try {
            func2(""); // 方法调用者try-catch捕获
        } catch (IOException e) {
            System.out.println("异常捕获Catch");
        }
        System.out.println("方法结束");
        // 方法开始 异常捕获Catch 方法结束
        
        System.out.println("方法开始");
        func2(""); // main方法内继续throws上抛将导致程序终止
        System.out.println("方法结束");
        // 方法开始
    }
}
